import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_video_app/common/constants/message.dart';
import 'file:///E:/Android_workspace/flutter_video_app/lib/page/discover/discovery_page.dart';
import 'file:///E:/Android_workspace/flutter_video_app/lib/page/home/home_page.dart';
import 'file:///E:/Android_workspace/flutter_video_app/lib/page/mine/mine_page.dart';
import 'file:///E:/Android_workspace/flutter_video_app/lib/page/rank/rank_page.dart';

class TabPageView extends StatefulWidget {
  @override
  State createState() => _TabPageViewState();
}

class _TabPageViewState extends State<TabPageView> {
  int currentIndex;
  PageController _pageController = PageController();
  List<BottomNavigationBarItem> _barItemList;

  @override
  void initState() {
    _barItemList = [
      _bottomNavigationBarItem(Message.home_page, Icons.home),
      _bottomNavigationBarItem(Message.discovery, Icons.favorite),
      _bottomNavigationBarItem(Message.hot, Icons.hot_tub_sharp),
      _bottomNavigationBarItem(Message.mine, Icons.menu),
    ];
    currentIndex=0;
    super.initState();
  }

  void _jumpToPage(int index) {
    _pageController.jumpToPage(index);
    setState(() {
      currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: currentIndex,
        type: BottomNavigationBarType.fixed, //显示标题
        items: _barItemList,
        onTap: _jumpToPage,
      ),
      body: PageView(
        controller: _pageController,
        physics: NeverScrollableScrollPhysics(),
        children: [
          HomePage(),
          DiscoveryPage(),
          RankPage(),
          MinePage(),
        ],
      ),
    );
  }

  BottomNavigationBarItem _bottomNavigationBarItem(
      String title, IconData iconData) {
    return new BottomNavigationBarItem(
      icon: Icon(iconData),
      label: title,
    );
  }
}
